// packagePlan/imgTemplate/imgTemplate.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    from: '',
    imgList: [],
    selectIndex: null,
    selectUrl: '',
    index: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options.index) {
      this.setData({
        index: options.index
      })
    }
    this.setData({
      from: options.from
    })

    // 个人主页
    if (this.data.from == 'homepage') {
      this.setData({
        imgList: [
          'https://elf.byxfd.com/avatar/me01.png',
          'https://elf.byxfd.com/avatar/me02.png',
          'https://elf.byxfd.com/avatar/me03.png',
          'https://elf.byxfd.com/avatar/me04.png',
          'https://elf.byxfd.com/avatar/me05.png',
          'https://elf.byxfd.com/avatar/me06.png',
          'https://elf.byxfd.com/avatar/me07.png',
          'https://elf.byxfd.com/avatar/me08.png'
        ]
      })
    }

    // 活动主题
    if (this.data.from == 'activity') {
      this.setData({
        imgList: [
          'https://elf.byxfd.com/avatar/bs01.png',
          'https://elf.byxfd.com/avatar/bs02.png',
          'https://elf.byxfd.com/avatar/bs03.png',
          'https://elf.byxfd.com/avatar/bs04.png',
          'https://elf.byxfd.com/avatar/bs05.png',
          'https://elf.byxfd.com/avatar/bs06.png',
          'https://elf.byxfd.com/avatar/bs07.png',
          'https://elf.byxfd.com/avatar/bs08.png'
        ]
      })
    }

    // 活动详情
    if (this.data.from == 'activityDetail') {
      this.setData({
        imgList: [
          'https://elf.byxfd.com/avatar/me01.png',
          'https://elf.byxfd.com/avatar/me02.png',
          'https://elf.byxfd.com/avatar/me03.png',
          'https://elf.byxfd.com/avatar/me04.png',
          'https://elf.byxfd.com/avatar/me05.png',
          'https://elf.byxfd.com/avatar/me06.png',
          'https://elf.byxfd.com/avatar/me07.png',
          'https://elf.byxfd.com/avatar/me08.png'
        ]
      })
    }

    // 比赛主题
    if (this.data.from == 'competition') {
      this.setData({
        imgList: [
          'https://elf.byxfd.com/avatar/bs01.png',
          'https://elf.byxfd.com/avatar/bs02.png',
          'https://elf.byxfd.com/avatar/bs03.png',
          'https://elf.byxfd.com/avatar/bs04.png',
          'https://elf.byxfd.com/avatar/bs05.png',
          'https://elf.byxfd.com/avatar/bs06.png',
          'https://elf.byxfd.com/avatar/bs07.png',
          'https://elf.byxfd.com/avatar/bs08.png'
        ]
      })
    }

    // 比赛详情
    if (this.data.from == 'competitionDetail') {
      this.setData({
        imgList: [
          'https://elf.byxfd.com/avatar/me01.png',
          'https://elf.byxfd.com/avatar/me02.png',
          'https://elf.byxfd.com/avatar/me03.png',
          'https://elf.byxfd.com/avatar/me04.png',
          'https://elf.byxfd.com/avatar/me05.png',
          'https://elf.byxfd.com/avatar/me06.png',
          'https://elf.byxfd.com/avatar/me07.png',
          'https://elf.byxfd.com/avatar/me08.png'
        ]
      })
    }

    // 作品主题
    if (this.data.from == 'work') {
      this.setData({
        imgList: [
          'https://elf.byxfd.com/avatar/bs01.png',
          'https://elf.byxfd.com/avatar/bs02.png',
          'https://elf.byxfd.com/avatar/bs03.png',
          'https://elf.byxfd.com/avatar/bs04.png',
          'https://elf.byxfd.com/avatar/bs05.png',
          'https://elf.byxfd.com/avatar/bs06.png',
          'https://elf.byxfd.com/avatar/bs07.png',
          'https://elf.byxfd.com/avatar/bs08.png'
        ]
      })
    }

    // 作品详情
    if (this.data.from == 'workDetail') {
      this.setData({
        imgList: [
          'https://elf.byxfd.com/avatar/me01.png',
          'https://elf.byxfd.com/avatar/me02.png',
          'https://elf.byxfd.com/avatar/me03.png',
          'https://elf.byxfd.com/avatar/me04.png',
          'https://elf.byxfd.com/avatar/me05.png',
          'https://elf.byxfd.com/avatar/me06.png',
          'https://elf.byxfd.com/avatar/me07.png',
          'https://elf.byxfd.com/avatar/me08.png'
        ]
      })
    }

    // 课程主题
    if (this.data.from == 'curriculum') {
      this.setData({
        imgList: [
          'https://elf.byxfd.com/avatar/bs01.png',
          'https://elf.byxfd.com/avatar/bs02.png',
          'https://elf.byxfd.com/avatar/bs03.png',
          'https://elf.byxfd.com/avatar/bs04.png',
          'https://elf.byxfd.com/avatar/bs05.png',
          'https://elf.byxfd.com/avatar/bs06.png',
          'https://elf.byxfd.com/avatar/bs07.png',
          'https://elf.byxfd.com/avatar/bs08.png'
        ]
      })
    }

    // 课程详情
    if (this.data.from == 'curriculumDetail') {
      this.setData({
        imgList: [
          'https://elf.byxfd.com/avatar/me01.png',
          'https://elf.byxfd.com/avatar/me02.png',
          'https://elf.byxfd.com/avatar/me03.png',
          'https://elf.byxfd.com/avatar/me04.png',
          'https://elf.byxfd.com/avatar/me05.png',
          'https://elf.byxfd.com/avatar/me06.png',
          'https://elf.byxfd.com/avatar/me07.png',
          'https://elf.byxfd.com/avatar/me08.png'
        ]
      })
    }

    // 课程详情
    if (this.data.from == 'avatar') {
      this.setData({
        imgList: [
          'https://elf.byxfd.com/avatar/me01.png',
          'https://elf.byxfd.com/avatar/me02.png',
          'https://elf.byxfd.com/avatar/me03.png',
          'https://elf.byxfd.com/avatar/me04.png',
          'https://elf.byxfd.com/avatar/me05.png',
          'https://elf.byxfd.com/avatar/me06.png',
          'https://elf.byxfd.com/avatar/me07.png',
          'https://elf.byxfd.com/avatar/me08.png'
        ]
      })
    }
  },

  confirm() {
    if (this.data.selectUrl.length <= 0) {
      wx.showToast({
        title: '请先选择图片',
        icon: 'none'
      })
      return
    }
    let pages = getCurrentPages() // 获取页面栈
    let returnpage = pages[pages.length - 2] // 上一个页面
    if (this.data.index == '2') {
      returnpage.setData({
        imgUrlDetail: this.data.selectUrl
      })
    } else {
      returnpage.setData({
        imgUrl: this.data.selectUrl
      })
    }
    wx.navigateBack({
      delta: 1
    })
  },

  selectImg(detail) {
    this.setData({
      selectUrl: detail.currentTarget.dataset.url
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {}
})
